<template>
    <el-card class="form-container" shadow="never">
        <el-form
                :model="store"
                ref="storeForm"
                label-width="150px"
                size="small"
                :rules="rules"
        >
            <el-form-item label="门店名称:" prop="name">
                <el-input v-model="store.name" class="input-width"></el-input>
            </el-form-item>
            <el-form-item label="门店地址:" prop="addressLat">
                <el-input v-model="store.addressLat" class="input-width"></el-input>
            </el-form-item>
            <el-form-item label="商户号:" prop="addressLat">
                <el-input v-model="store.mchId" class="input-width"></el-input>
            </el-form-item>
            <el-form-item label="分账比例:" prop="addressLat">
                <el-input v-model="store.scale" class="input-width"></el-input>
            </el-form-item>
            <el-form-item label="联系电话:" prop="servicePhone">
                <el-input v-model="store.servicePhone" class="input-width"></el-input>
            </el-form-item>
            <el-form-item label="位置经度:" prop="longitude">
                <el-input v-model="store.longitude" class="input-width"></el-input>
            </el-form-item>
            <el-form-item label="位置维度:" prop="latitude">
                <el-input v-model="store.latitude" class="input-width"></el-input>
            </el-form-item>
            <el-form-item label="营业时间:" prop="onlineTime">
                <el-input v-model="store.onlineTime" class="input-width"></el-input>
            </el-form-item>
            <el-form-item label="预留打扫时间:" prop="onlineTime">
                <el-input v-model="store.dasaoTime" class="input-width"></el-input>
            </el-form-item>
            <el-form-item label="美团店铺ID:" prop="openShopUuid">
                <el-input v-model="store.openShopUuid" class="input-width"></el-input>
            </el-form-item>
            <el-form-item label="抖音店铺ID:" prop="douyinPoiid">
                <el-input v-model="store.douyinPoiid" class="input-width"></el-input>
            </el-form-item>
            <el-form-item label="店铺图:">
                <single-upload v-model="store.img1"></single-upload>
            </el-form-item>
            <el-form-item label="营业状态:">
                <el-radio-group v-model="store.onlineStatus">
                    <el-radio :label="'正在装修'">正在装修</el-radio>
                    <el-radio :label="'正在营业'">正在营业</el-radio>
                    <el-radio :label="'暂未营业'">暂未营业</el-radio>
                </el-radio-group>
            </el-form-item>
            <el-form-item label="门店公告:">
                <el-input v-model="store.notice" class="input-width"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="onSubmit('storeForm')"
                >提交
                </el-button
                >
            </el-form-item>
        </el-form>
    </el-card>
</template>
<script>
    import SingleUpload from "@/components/Upload/singleUpload";
    import {currentStore, updateStore} from "@/api/qsg/store";

    const defaultDevice = {
        deviceCode: '',
        machineName: '',
        area: ''
    };

    export default {
        components: {SingleUpload},
        props: {
            isEdit: {
                type: Boolean,
                default: false,
            },
        },
        data() {
            return {
                store: null,
                rules: {
                    longitude: [
                        {required: true, message: "请输入经度", trigger: "blur"},
                    ],
                    latitude: [{required: true, message: "请输入纬度", trigger: "blur"}],
                }
            };
        },
        created() {
            currentStore().then((response) => {
                this.store = response.data;
            });
        },
        methods: {
            onSubmit(formName) {
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        this.$confirm("是否提交数据", "提示", {
                            confirmButtonText: "确定",
                            cancelButtonText: "取消",
                            type: "warning",
                        }).then(() => {
                            updateStore(this.store.id, this.store).then(
                                (response) => {
                                    this.$refs[formName].resetFields();
                                    this.$message({
                                        message: "修改成功",
                                        type: "success",
                                        duration: 1000,
                                    });
                                }
                            );
                        });
                    } else {
                        this.$message({
                            message: "验证失败",
                            type: "error",
                            duration: 1000,
                        });
                        return false;
                    }
                });
            },
            resetForm(formName) {
                this.$refs[formName].resetFields();
                this.device = Object.assign({}, defaultDevice);
            },
        },
    };
</script>
<style scoped>
    .input-width {
        width: 70%;
    }
</style>


